/**
 * @file src/ScoringMatrix.cpp
 *
 * @date 25-jul-2013
 *
 * @author Youri Hoogstrate
 *
 * @section LICENSE
 * yh-kt-fold can predict RNA 2D structures including K-turns.
 * Copyright (C) 2012-2013 Youri Hoogstrate
 *
 * This file is part of yh-kt-fold.
 *
 * yh-kt-fold is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * yh-kt-fold is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */



#include "ScoringMatrix.h"



/**
 * @brief
 *
 * @date 25-jul-2013
 *
 * @todo work with templates;
 * - Float for Energy values (V & W matrix)
 * - Int for identifiers (Motif objects)
 *
 * @section DESCRIPTION
 * For a matrix of n*n, all values (x,x) for 0 < x < n are initialized with a: 0
 * Similarly, all values (x,x-1) for 1 < x < n are initialized with a: 0
 *
 * Thus, only the positions in the matrix where x > y have to be located.
 * For a matrix of size: 4 * 4 (i = initation, s = store):
 *
 * [0,0][1,0][2,0][3,0]   [ i ][ s ][ s ][ s ]
 * [0,1][1,1][2,1][3,1]   [ i ][ i ][ s ][ s ]
 * [0,2][1,2][2,2][3,2]   [   ][ i ][ i ][ s ]
 * [0,3][1,3][2,3][3,3]   [   ][   ][ i ][ i ]
 *
 * size = ((n-1)/2) * n
 *
 * [ i ][ s ][ s ][ s ][ s ]
 * [ i ][ i ][ s ][ s ][ s ]
 * [   ][ i ][ i ][ s ][ s ]
 * [   ][   ][ i ][ i ][ s ]
 * [   ][   ][   ][ i ][ i ]
 */
ScoringMatrix::ScoringMatrix(unsigned int length)
{
	//create vector of size = ((n-1)/2) * n
	
	printf("ALIVE\n");
	
	length = ((length - 1) / 2) * length;
	
	this->m = std::vector<float>(length);
}



/**
 * @brief
 *
 * @date 25-jul-2013
 */
float ScoringMatrix::get(int x, int y)
{
	switch(this->get_position(x, y))
	{
		case -1://this is an init location
			return GIBBS_ENERGY_INIT;
			break;
		case -2:
			// error, out of bound
			break;
		default:
			// return vector[this->get_position(x,y)];
			break;
	}
}



/**
 * @brief
 *
 * @date 25-jul-2013
 */
int ScoringMatrix::get_position(int x, int y)
{
	//[1,0] -> 0
	// if init: if(x == y || x == (y+1))
	//
	//    return -1 (constant)
	// elif outofbound (x < y)
	//    return -2 (constant)
	//
	// else:
	//
	int n = this->length - y  + 1;
	int r = n - y;
	
	int total = ((n - 1) / 2) * n;
	int bottom = ((r - 1) / 2) * r;
	
	//int location = 6 - ((n - 1) / 2) * n;
	// plus last line
	
	int row = (n - 1) - x;
	
	return total - bottom - row;
}



/**
 * @brief
 *
 * @date 25-jul-2013
 */
void ScoringMatrix::set(int x, int y, float value)
{

}